//
//  AYSHomeTableViewCell.m
//  AiYingShiProject
//
//  Created by lanou on 15/10/27.
//  Copyright (c) 2015年 李晓理. All rights reserved.
//

#import "AYSHomeTableViewCell.h"
#import "AYSHomeCollectionViewCell.h"
#import <UIImageView+WebCache.h>
#import "AYSHomePageModel.h"
#import "AYSCommonPlayViewController.h"
@interface AYSHomeTableViewCell ()<UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout>

@end

@implementation AYSHomeTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        _categoryImage = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 18, 18)];
        [self.contentView addSubview:_categoryImage];
        
        _categoryLable = [[UILabel alloc] initWithFrame:CGRectMake(35, 5, 100, 30)];
        _categoryLable.font = [UIFont boldSystemFontOfSize:17];
        _categoryLable.textColor = [UIColor whiteColor];
        [self.contentView addSubview:_categoryLable];
        
        _moreButton = [[UIButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - 50, 10, 60, 30)];
        _moreButton.titleLabel.font = [UIFont systemFontOfSize:15];
        [_moreButton setTitle:@"更多" forState:(UIControlStateNormal)];
        [self.contentView addSubview:_moreButton];
        
        // 创建collectionView
        [self getCollectionView];
        
    }
    return self;
}

- (void)getCollectionView
{
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.minimumLineSpacing = 10;
    layout.itemSize = CGSizeMake(100, 200);
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(10, 35, SCREEN_WIDTH - 10, 230) collectionViewLayout:layout];
    _collectionView.backgroundColor = [UIColor blackColor];
    _collectionView.dataSource = self;
    _collectionView.delegate = self;
    _collectionView.showsHorizontalScrollIndicator = FALSE;
    [self.contentView addSubview:_collectionView];
    
    // 注册
    [_collectionView registerClass:[AYSHomeCollectionViewCell class] forCellWithReuseIdentifier:@"reuse"];
    

}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
       return _HomeDataArr.count;
}


- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    AYSHomeCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"reuse" forIndexPath:indexPath];
    if (indexPath.item >= 0 && indexPath.row < _HomeDataArr.count)
    {
        AYSHomePageModel *model = _HomeDataArr[indexPath.item];
        
        [cell.picture sd_setImageWithURL:[NSURL URLWithString:model.vthumburl]];
        cell.nameLable.text = model.programname;
        cell.detialLable.text = model.shortdesc;
    }
   
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    AYSCommonPlayViewController *commonPlayVC = [[AYSCommonPlayViewController alloc] init];
    AYSHomePageModel *model = _HomeDataArr[indexPath.row];
    commonPlayVC.programeID = model.programID;
    [self.navigationController pushViewController:commonPlayVC animated:YES];
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
